<?php
class DBMReflectionHelper{
	const IS_PREFIX		= "is";
	const GET_PREFIX 	= "get";
	const SET_PREFIX 	= "set";
	
	public static function findGetter($className, $attribute){
		// check if the class exists
		if(!class_exists($className, true)){
			throw new Exception("The class " . $className . " doesn't exists!");
		}

		// create the variables
		$methods = array();
		
		// create the possible method names
		$methods[] = self::GET_PREFIX .ucwords($attribute);
		$methods[] = self::IS_PREFIX .ucwords($attribute); 

		// create the reflection object
		$reflectionClass = new ReflectionClass($className);
		
		foreach($methods as $method){
			// check if the method exists
			if($reflectionClass->hasMethod($method)){
				return $method;
			}	
		}
		
		// the method doesn't exists, throws an exception
		throw new Exception("The class " . $className . " doesn't have the getter method for the attribute " . $attribute . " !");
	}
	
	public static function findSetter($className, $attribute){
		// check if the class exists
		if(!class_exists($className, true)){
			throw new Exception("The class " . $className . " doesn't exists!");
		}
		
		// get the method name
		$methodName = self::SET_PREFIX .ucwords($attribute);

		// create the reflection object
		$reflectionClass = new ReflectionClass($className);
		
		// check if the method exists
		if($reflectionClass->hasMethod($methodName)){
			return $methodName;
		} else {
			throw new Exception("The class " . $className . " doesn't have the getter method for the attribute " . $attribute . " !");
		}
	}
}
?>